import com.dinmax.flash.draw.control.button.*;
import com.dinmax.flash.draw.control.MovieClipHelper;
import com.dinmax.flash.draw.common.Point;

class PressButtonControlDraggable extends PressButtonControl{
	
	private var buttonView:PressButtonView;
	private var base:MovieClip;
	private var min:Point;
	private var max:Point;

	function PressButtonControlDraggable(container:MovieClip, view:PressButtonView){
		super(container);
		if(view==undefined){
			buttonView=new PressButtonViewClassic();
		} else {
			buttonView=view;
		}
	}

	function getView():PressButtonView{
		return buttonView;
	}
	
	function disable(){
		getView().buttonDisable(base);
	}
	function enable(){
		getView().buttonNormal(base);
	}
	function draw(){
		reDraw();
	}
	function reDraw(){
		buttonView.reset();
		//Creo el movieBase
		removeMovieClip(base);
		base=createMovieClip();
		base._x=getLocation().getX();
		base._y=getLocation().getY();
		
		//tengo que setearle propiedades porque el flash es puto
		base.width=getSize().getX();
		base.height=getSize().getY();
		
		//dibujo el borde el fondo y seteo el texto
		buttonView.border(base); //listView.border(//el movie Base);
		buttonView.setText(getLabel());
		MovieClipHelper.setEventListener(base, this);				
			
	}
	function setMin(min:Point){
		this.min=min;
	}
	function setMax(max:Point){
		this.max=max;
	}
	
	function onPress(source:MovieClip):Void{
		getView().buttonPress(source);
		// ¿ de dónde sale ese +5 ?
		source.startDrag(true, min.getX(), min.getY(), max.getX(), max.getY()+5);
	};
	function onRelease(source:MovieClip):Void{
		getView().buttonNormal(source);
		setLocation(new Point(getLocation().getX(), source._y));
		source.stopDrag();
		select();
	};
	function onReleaseOutside(source:MovieClip):Void{
		onRelease(source);
	};
	function onRollOut(source:MovieClip):Void{
		getView().buttonNormal(source);
	};
	function onRollOver(source:MovieClip):Void{
		getView().buttonHover(source);
	};


}